#ifndef _HAVE_BLOCK_H
#define _HAVE_BLOCK_H

#include <stdint.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

struct block;
typedef struct block block_t;


/**
 * @brief 创建一个块
 * @param size 块的大小
 * @return 成功返回块指针,失败返回NULL
 */
block_t *block_new(size_t size);

/**
 * @brief 删除块以及append的块
 * @param blk 要删除的块
 */
void block_delete(block_t *blk);


void block_reset(block_t *blk);
/**
 * @brief
 * @param blk
 * @return
 */
block_t *block_next(block_t *blk);
block_t *block_prev(block_t *blk);
void block_append(block_t *blk_cur, block_t *blk);
void block_remove(block_t *blk);
size_t block_get_free_size(block_t *blk);
size_t block_get_used_size(block_t *blk);
ssize_t block_read(block_t *blk, uint8_t *rbuf, size_t len);
ssize_t block_write(block_t *blk, uint8_t *wbuf, size_t len);
int32_t block_isreadable(block_t *blk);
int32_t block_iswriteable(block_t *blk);
#ifdef __cplusplus
}
#endif

#endif /* _HAVE_BLOCK_H */
